package cn.gcc.domain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2017-07-25.
 */
@Component(value = "user")
//@Component这里说明是spring的组件（管理对象）  除了这个还有
//@Service(value = "user") service层的管理对象
//@Repository(value = "user") dao层的管理对象
//@Controller(value = "user") web层的对象
@Scope(value = "prototype")
public class User {
    @Value(value = "Pro")
    private String username;
    @Value(value = "root")
    private String password;
    @Value(value = "20")
    private int age;
//    @Autowired//自动装配，但是这里存在一个问题，
    // 因为这是给它在容器中找到相匹配的对象注入，如果有两个同类型的对象无法具体选择，
    // 所以需要另一个注解（@Qualifier）来完善
//    @Qualifier(value = "car")
    @Resource(name = "car2")
    private Car car;

    public User() {
//        System.out.println("User()");
    }

    public User(String username, Car car) {
//        System.out.println("User(String username, Car car)");
        this.username = username;
        this.car = car;
    }

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        this.car = car;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void init(){
        System.out.println("调用了初始化方法");
    }


    public void destroy(){
        System.out.println("调用了销毁方法");
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", age=" + age +
                ", car=" + car +
                '}';
    }
}
